/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.andersen.web.beans;

import com.andersen.database.entity.ComponentEntity;
import java.text.SimpleDateFormat;

/**
 *
 * @author Corvus 11
 */
public class ComponentCommandForm {
    
    private long id;
    private long typeId;
    private String description;
    private String buyDateString;
    private String warrantyEndDateString;
    private String serial;
    private boolean deleted;
    private String typeName;
    private boolean validationError = false;

    public static ComponentCommandForm fromEntity(ComponentEntity entity) {
        ComponentCommandForm f = new ComponentCommandForm();
        f.setId(entity.getId());
        f.setTypeId(entity.getTypeId());
        f.setDescription(entity.getDescription());
        f.setSerial(entity.getSerial());
        f.setDeleted(entity.getDeleted());
        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
        if (entity.getByDate() != null) f.setBuyDateString(format.format(entity.getByDate()));
        else f.setBuyDateString("");
        if (entity.getWarrantyEndDate() != null) f.setWarrantyEndDateString(format.format(entity.getWarrantyEndDate()));
        else f.setWarrantyEndDateString("");
        if (entity.getComponentType() != null) f.setTypeName(entity.getComponentType().getName());
        else f.setTypeName("");
        return f;
    }
    
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getTypeId() {
        return typeId;
    }

    public void setTypeId(long type_id) {
        this.typeId = type_id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getBuyDateString() {
        return buyDateString;
    }

    public void setBuyDateString(String byDateString) {
        this.buyDateString = byDateString;
    }

    public String getWarrantyEndDateString() {
        return warrantyEndDateString;
    }

    public void setWarrantyEndDateString(String warrantyEndDateString) {
        this.warrantyEndDateString = warrantyEndDateString;
    }

    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public boolean isValidationError() {
        return validationError;
    }

    public void setValidationError(boolean validationError) {
        this.validationError = validationError;
    }

    @Override
    public String toString() {
        return "ComponentCommandForm{" + 
                "id=" + id + 
                ", typeId=" + typeId + 
                ", description=" + description + 
                ", buyDateString=" + buyDateString + 
                ", warrantyEndDateString=" + warrantyEndDateString + 
                ", serial=" + serial + 
                ", deleted=" + deleted + 
                ", typeName=" + typeName + 
                ", validationError=" + validationError +
                '}';
    }

    
    
    
    
}
